package com.jy.adscm.hcPlan.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.hcPlan.bean.HcPlanAfterFinalAssemblyExample;
import com.jy.adscm.hcPlan.service.HcPlanAfterFinalAssemblyExampleService;
import com.jy.adscm.hcPlan.service.HcPlanFinalAssemblyService;
import com.jy.adscm.hcPlan.service.HcPlanMakePartExampleService;
import com.jy.adscm.hcPlan.service.HcPlanMakePartMaterielExampleService;
import com.jy.adscm.support.SimpleCoreResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 单次销售计划耗材总装后的其他计划项目标准配置表 前端控制器
 * </p>
 *
 * @author yyy
 * @since 2018-08-13
 */
@RestController
@RequestMapping("/adscm/hcplan/hcPlanAfterFinalAssembly")
public class HcPlanAfterFinalAssemblyExampleController {

    @Autowired
    HcPlanAfterFinalAssemblyExampleService hcPlanAfterFinalAssemblyExampleService;
    @Autowired
    HcPlanFinalAssemblyService hcPlanFinalAssemblyService;
    @Autowired
    HcPlanMakePartExampleService hcPlanMakePartExampleService;
    @Autowired
    HcPlanMakePartMaterielExampleService hcPlanMakePartMaterielExampleService;


    /**
     *  查询某次总装的单次其他计划配置
     * @param finalAssemblyId
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/queryHcPlanAfterFinalAssemblyExample/{finalAssemblyId}")
    public SimpleCoreResponse queryHcPlanFinalAssemblyList(@PathVariable Long finalAssemblyId) throws AdscmSystemException{

        Wrapper<HcPlanAfterFinalAssemblyExample> wrapper = new EntityWrapper<>();
//        wrapper.where("final_assembly = ? ",finalAssemblyId);
        wrapper.eq("final_assembly",finalAssemblyId);

        List<HcPlanAfterFinalAssemblyExample> list = hcPlanAfterFinalAssemblyExampleService.selectList(wrapper);


        return new SimpleCoreResponse("200","查询成功",list);

    }
    /**
     *  修改某次总装的单次其他计划配置
     * @param content
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/editHcPlanAfterFinalAssemblyExample")
    public SimpleCoreResponse editHcPlanAfterFinalAssemblyExample(@RequestBody HcPlanAfterFinalAssemblyExample[] content) throws AdscmSystemException{

        if (content != null && content.length>0){

            hcPlanAfterFinalAssemblyExampleService.updateAllColumnBatchById(Arrays.asList(content));
            hcPlanFinalAssemblyService.reEditFinalAssembly(content[0].getFinalAssembly());

            //装配单批次零件制造的数据
            hcPlanMakePartExampleService.loadHcPartExampleByAssemblyId_new1(content[0].getFinalAssembly());

            //装配单批次物料采购数据
            hcPlanMakePartMaterielExampleService.loadHcPartMaterielExampleByAssemblyId(content[0].getFinalAssembly());
        }

        return new SimpleCoreResponse("200","修改成功",null);

    }

}

